<template>
	<view class="my-page-content">
		<web-view :src="aboutus"></web-view>
		<!-- <view v-html="aboutus"></view> -->
		<!-- <view class="infoContentStyle" v-for="(item, index) in aboutus" :key="index">
			<rich-text v-if="item.type=='rich-text'" class="content-container ql-editor"
				:nodes="item.value"></rich-text>
			<video referrer-policy="origin" :autoplay="false" controls v-if="item.type=='video' && item.value != '' "
				:src="item.value" style="width:100%;height: 150px" frameborder="0">
			</video>
		</view> -->


	</view>
</template>

<script>
	
	export default {
	
		data() {
			return {
				aboutus: ''
			}
		},
		methods: {
			getConfiguration() {
				this.$http.getConfiguration().then(res => {
					res.forEach(item => {
						if (item.type == 'aboutus') {
							this.aboutus =  item.content;
							// this.aboutus = this.formatContent(item.content);
							console.log(this.aboutus)
						}
					})
				});
			},
			formatContent(content) {
				let article = content.replace(/(\<img|\<p)/gi, function($0, $1) {
					return {
						"<img": '<img style="max-width:100%;height:auto;display:block;" ',
						"<p": '<p style="color:#333" ',
						"<article": "<div",
						"</article": "</div",
						"<header": "<div",
						"</header": "</div"
					} [$1];
				});
				let videoList = [];
				let videoReg = /<video.*?(?:>|\/>)/gi; //匹配到字符串中的 video 标签
				let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; //匹配到字符串中的 video 标签 的路径
				let arr = article.match(videoReg) || []; // arr 为包含所有video标签的数组
				let articleList = article.split('</video>') // 把字符串  从视频标签分成数组
				arr.forEach((item, index) => {
					var src = item.match(srcReg);
					videoList.push(src[1]) //所要显示的字符串中 所有的video 标签 的路径
				})
				let needArticleList = [];
				articleList.forEach((item, index) => {
					if (item != "" && item != undefined) { //  常见的标签渲染
						needArticleList.push({
							type: 'rich-text',
							value: item + "</video>"
						});
					}
					let articleListLength = articleList.length; // 插入到原有video 标签位置
					if (index < articleListLength && videoList[index] != undefined) {
						needArticleList.push({
							type: 'video',
							value: videoList[index]
						})
					}
				})
				return needArticleList

			}


		},
		onLoad() {
			this.getConfiguration();
		}
	}
</script>

<style scoped lang="scss">
	// .my-page-content {
	// 	img {
	// 		width: 100%;
	// 	}
	// }
	// img {
	// 	  max-width: 100%!important;
	// 	}
</style>